package de.fhl.view;

/**
 * Ueberschrift:  OnlineWahl
 * Copyright:     Copyright (c) 2010 
 * Organisation:  FH Luebeck - Virtuelle FH
 */

import de.fhl.controller.*;
import de.fhl.model.*;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.util.Observable;
import java.util.Observer;
 
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;

/**
 * Die Klasse WahlzettelView ist die View des Wahlzettels über die GUI<br>
 * 
 * @author Achim Krumrein (krumreia@stud.fh-luebeck.de)
 * @author Thomas Weber (webertho@googlemail.de)
 * @version 1.0
 */
public class WahlzettelView extends JFrame implements Observer
{	// MVC Instanzen
	private WahlzettelController	controller;
	private WahlzettelModel		model;
 
	// weitere lokale Variablen...
	private JLabel erstStimme;
	private JRadioButton kandidat1;
	private JTextArea textKan11;
	private JTextArea textKan21;
	private JTextArea textKan31;
	private JTextArea textKan41;
	private JTextArea textKan51;
	private JTextArea textKan61;
	private JTextArea textKan71;
	private JTextArea textKan12;
	private JTextArea textKan22;
	private JTextArea textKan32;
	private JTextArea textKan42;
	private JTextArea textKan52;
	private JTextArea textKan62;
	private JTextArea textKan72;
	private JRadioButton kandidat2;
	private JRadioButton kandidat3;
	private JRadioButton kandidat4;
	private JRadioButton kandidat5;
	private JRadioButton kandidat6;
	private JRadioButton kandidat7;
	private ButtonGroup kandidaten;

	private JLabel zweitStimme;
	private JRadioButton partei1;
	private JTextArea textArea11;
	private JTextArea textArea12;
	private JRadioButton partei2;
	private JTextArea textArea21;
	private JTextArea textArea22;
	private JRadioButton partei3;
	private JTextArea textArea31;
	private JTextArea textArea32;
	private JRadioButton partei4;
	private JTextArea textArea41;
	private JTextArea textArea42;
	private JRadioButton partei5;
	private JTextArea textArea51;
	private JTextArea textArea52;
	private JRadioButton partei6;
	private JTextArea textArea61;
	private JTextArea textArea62;
	private JRadioButton partei7;
	private JTextArea textArea71;
	private JTextArea textArea72;
	private ButtonGroup parteien;

	private JButton saveButton;
	private JButton closeButton;

	private Font font1;
	private Font font2;
	private Font font3;
 
	// Initialisierung Konstruktor
    public WahlzettelView(WahlzettelModel model)
    {
    	this.model = model;
    	this.model.addObserver(this);
    	this.controller = new WahlzettelController(this,model);
    	initGUI();
    }
 
    // Initialisierung der Frame und GUI Elemente
    private void initGUI()
    {
    	// Frame (extends JFrame)
		setTitle("Online Wahl 2010");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLayout(new BorderLayout());
		setSize(880,870);
		setResizable(false);
		setVisible(true);
		
		font1 = new Font("SansSerif", Font.ROMAN_BASELINE, 20);
		font2 = new Font("SansSerif", Font.ROMAN_BASELINE, 14);
		font3 = new Font("SansSerif", Font.ROMAN_BASELINE, 12);
		

	    // Andere GUI Elemente...

		/**
		 * Erststimme
		 */
		erstStimme = new JLabel("Erststimme");
		erstStimme.setFont(font1);
		
		kandidat1 = new JRadioButton("CDU");
		kandidat1.setFont(font2);
		textKan11 = new JTextArea("Textarea11");
		textKan11.setEditable(false);
		textKan11.setFont(font3);
		textKan12 = new JTextArea("Textarea12");
		textKan12.setEditable(false);
		textKan12.setFont(font2);
		
		kandidat2 = new JRadioButton("SPD");
		kandidat2.setFont(font2);
		textKan21 = new JTextArea("Textarea21");
		textKan21.setEditable(false);
		textKan21.setFont(font3);
		textKan22 = new JTextArea("Textarea22");
		textKan22.setEditable(false);
		textKan22.setFont(font2);
		
		kandidat3 = new JRadioButton("Grüne");
		kandidat3.setFont(font2);
		textKan31 = new JTextArea("Textarea31");
		textKan31.setEditable(false);
		textKan31.setFont(font3);
		textKan32 = new JTextArea("Textarea32");
		textKan32.setEditable(false);
		textKan32.setFont(font2);
		
		kandidat4 = new JRadioButton("FDP");
		kandidat4.setFont(font2);
		textKan41 = new JTextArea("Textarea41");
		textKan41.setEditable(false);
		textKan41.setFont(font3);
		textKan42 = new JTextArea("Textarea42");
		textKan42.setEditable(false);
		textKan42.setFont(font2);
		
		kandidat5 = new JRadioButton("Die Tierschutzpartei");
		kandidat5.setFont(font2);
		textKan51 = new JTextArea("Textarea51");
		textKan51.setEditable(false);
		textKan51.setFont(font3);
		textKan52 = new JTextArea("Textarea52");
		textKan52.setEditable(false);
		textKan52.setFont(font2);
		
		kandidat6 = new JRadioButton("Familie");
		kandidat6.setFont(font2);
		textKan61 = new JTextArea("Textarea61");
		textKan61.setEditable(false);
		textKan61.setFont(font3);
		textKan62 = new JTextArea("Textarea62");
		textKan62.setEditable(false);
		textKan62.setFont(font2);
		
		kandidat7 = new JRadioButton("Piraten");
		kandidat7.setFont(font2);
		textKan71 = new JTextArea("Textarea71");
		textKan71.setEditable(false);
		textKan71.setFont(font3);
		textKan72 = new JTextArea("Textarea72");
		textKan72.setEditable(false);
		textKan72.setFont(font2);
		
		kandidaten = new ButtonGroup();
		kandidaten.add(kandidat1);
		kandidaten.add(kandidat2);
		kandidaten.add(kandidat3);
		kandidaten.add(kandidat4);
		kandidaten.add(kandidat5);
		kandidaten.add(kandidat6);
		kandidaten.add(kandidat7);

		JPanel kandidatPane = new JPanel();
		kandidatPane.setLayout(new GridBagLayout());
		//kandidatPane.setSize(500, 2000);
		GridBagConstraints gBC1 = new GridBagConstraints();
		gBC1.fill = GridBagConstraints.BOTH;


		kandidatPane.setBorder(new LineBorder(Color.black));
		gBC1.weightx = 0.5;
		gBC1.gridx = 0;
		gBC1.gridy = 0;
		kandidatPane.add(erstStimme, gBC1);
		
		gBC1.ipady = 15;
		gBC1.gridx = 0;
		gBC1.gridy = 1;
		kandidatPane.add(kandidat1, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 1;
		kandidatPane.add(textKan11, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 2;
		kandidatPane.add(textKan12, gBC1);
		
		gBC1.ipady = 15;
		gBC1.gridx = 0;
		gBC1.gridy = 3;
		kandidatPane.add(kandidat2, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 3;
		kandidatPane.add(textKan21, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 4;
		kandidatPane.add(textKan22, gBC1);
		
		gBC1.ipady = 15;
		gBC1.gridx = 0;
		gBC1.gridy = 5;
		kandidatPane.add(kandidat3, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 5;
		kandidatPane.add(textKan31, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 6;
		kandidatPane.add(textKan32, gBC1);		
		
		gBC1.ipady = 15;
		gBC1.gridx = 0;
		gBC1.gridy = 7;
		kandidatPane.add(kandidat4, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 7;
		kandidatPane.add(textKan41, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 8;
		kandidatPane.add(textKan42, gBC1);
		
		gBC1.ipady = 15;
		gBC1.gridx = 0;
		gBC1.gridy = 9;
		kandidatPane.add(kandidat5, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 9;
		kandidatPane.add(textKan51, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 10;
		kandidatPane.add(textKan52, gBC1);
		
		gBC1.ipady = 15;
		gBC1.gridx = 0;
		gBC1.gridy = 11;
		kandidatPane.add(kandidat6, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 11;
		kandidatPane.add(textKan61, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 12;
		kandidatPane.add(textKan62, gBC1);
		
		gBC1.ipady = 15;
		gBC1.gridx = 0;
		gBC1.gridy = 13;
		kandidatPane.add(kandidat7, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 13;
		kandidatPane.add(textKan71, gBC1);
		gBC1.gridx = 1;
		gBC1.gridy = 14;
		kandidatPane.add(textKan72, gBC1);

		/**
		 * Zweitstimmen
		 */
		zweitStimme = new JLabel("Zweitstimme");
		zweitStimme.setFont(font1);
		partei1 = new JRadioButton("CDU");
		partei1.setFont(font2);
		textArea11 = new JTextArea("Christlich Demokratische\n"
				+ "Union Deutschlands");
		textArea11.setEditable(false);
		textArea11.setFont(font2);
		textArea12 = new JTextArea("Dr. Jürgen Rüttgers, Eckhard Uhlenberg,\n"
				+ "Regina van Dinther, Karl-Josef Laumann,\n" + "Armin Laschet");
		textArea12.setEditable(false);
		textArea12.setFont(font3);
		partei2 = new JRadioButton("SPD");
		partei2.setFont(font2);
		textArea21 = new JTextArea("Sozialdemokratische\n"
				+ "Partei Deutschlands");
		textArea21.setEditable(false);
		textArea21.setFont(font2);
		textArea22 = new JTextArea("Hannelore Kraft, Norbert Römer,\n"
				+ "Svenja Schulze, Hans-Willi Körfges\n" + "Ute Schäfer");
		textArea22.setEditable(false);
		textArea22.setFont(font3);
		partei3 = new JRadioButton("GRÜNE");
		partei3.setFont(font2);
		textArea31 = new JTextArea("Bündnis 90/Die GRÜNEN");
		textArea31.setEditable(false);
		textArea31.setFont(font2);
		textArea32 = new JTextArea("Sylvia Löhrmann,Reiner Priggen,\n"
				+ "Barbara Steffens, Johannes Remmel,\n" + "Sigrid Beer");
		textArea32.setEditable(false);
		textArea32.setFont(font3);
		partei4 = new JRadioButton("FDP");
		partei4.setFont(font2);
		textArea41 = new JTextArea("Freie Demokratische\n" + "Partei");
		textArea41.setEditable(false);
		textArea41.setFont(font2);
		textArea42 = new JTextArea("Dr. Andreas Pinkwart, Dr. Ingo Wolf,\n"
				+ "Dr. Gerhard Papke, Angela Freimuth,\n" + "Dr. Robert Orth");
		textArea42.setEditable(false);
		textArea42.setFont(font3);
		partei5 = new JRadioButton("Die Tierschutzpartei");
		partei5.setFont(font2);
		textArea51 = new JTextArea("Mensch Umwelt Tierschutz");
		textArea51.setEditable(false);
		textArea51.setFont(font2);
		textArea52 = new JTextArea("Monika Thau, Michael Sielhoff,\n"
				+ "Marion Anneliese Schäfer, Sara Kaute,\n" + "Sascha-Liesa Germer");
		textArea52.setEditable(false);
		textArea52.setFont(font3);
		partei6 = new JRadioButton("FAMILIE");
		partei6.setFont(font2);
		textArea61 = new JTextArea("Familien-Partei\n" + "Deutschlands");
		textArea61.setEditable(false);
		textArea61.setFont(font2);
		textArea62 = new JTextArea("Maria Hartmann, Dr. Dorthea Böhm,\n"
				+ "Heiner Leslie, Otto Chritinick,\n" + "Heinrich Oldenburg");
		textArea62.setEditable(false);
		textArea62.setFont(font3);
		partei7 = new JRadioButton("PIRATEN");
		partei7.setFont(font2);
		textArea71 = new JTextArea("Piratenpartei Deutschland");
		textArea71.setEditable(false);
		textArea71.setFont(font2);
		textArea72 = new JTextArea("Nicolaus Kern, Hans Immanuel Herbers,\n"
				+ "Dirk Schatz, Simone Brand,\n" + "Christian Horchert");
		textArea72.setEditable(false);
		textArea72.setFont(font3);

		parteien = new ButtonGroup();
		parteien.add(partei1);
		parteien.add(partei2);
		parteien.add(partei3);
		parteien.add(partei4);
		parteien.add(partei5);
		parteien.add(partei6);
		parteien.add(partei7);

		JPanel parteiPane = new JPanel();
		parteiPane.setLayout(new GridBagLayout());
		//parteiPane.setSize(500, 800);
		GridBagConstraints gBC2 = new GridBagConstraints();
		gBC2.fill = GridBagConstraints.BOTH;

		parteiPane.setBorder(new LineBorder(Color.black));
		gBC2.weightx = 0.5;
		gBC2.gridx = 0;
		gBC2.gridy = 0;
		parteiPane.add(zweitStimme, gBC2);
		gBC2.ipady = 15;
		gBC2.gridx = 0;
		gBC2.gridy = 1;
		parteiPane.add(partei1, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 1;
		parteiPane.add(textArea11, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 2;
		parteiPane.add(textArea12, gBC2);
		gBC2.ipady = 15;
		gBC2.gridx = 0;
		gBC2.gridy = 3;
		parteiPane.add(partei2, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 3;
		parteiPane.add(textArea21, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 4;
		parteiPane.add(textArea22, gBC2);
		gBC2.ipady = 15;
		gBC2.gridx = 0;
		gBC2.gridy = 5;
		parteiPane.add(partei3, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 5;
		parteiPane.add(textArea31, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 6;
		parteiPane.add(textArea32, gBC2);
		gBC2.ipady = 15;
		gBC2.gridx = 0;
		gBC2.gridy = 7;
		parteiPane.add(partei4, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 7;
		parteiPane.add(textArea41, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 8;
		parteiPane.add(textArea42, gBC2);
		gBC2.ipady = 15;
		gBC2.gridx = 0;
		gBC2.gridy = 9;
		parteiPane.add(partei5, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 9;
		parteiPane.add(textArea51, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 10;
		parteiPane.add(textArea52, gBC2);
		gBC2.ipady = 15;
		gBC2.gridx = 0;
		gBC2.gridy = 11;
		parteiPane.add(partei6, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 11;
		parteiPane.add(textArea61, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 12;
		parteiPane.add(textArea62, gBC2);
		gBC2.ipady = 15;
		gBC2.gridx = 0;
		gBC2.gridy = 13;
		parteiPane.add(partei7, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 13;
		parteiPane.add(textArea71, gBC2);
		gBC2.gridx = 1;
		gBC2.gridy = 14;
		parteiPane.add(textArea72, gBC2);

		saveButton = new JButton("Speichern");
		saveButton.setActionCommand("fromSaveButton");
		saveButton.addActionListener(controller);
		closeButton = new JButton("Schliessen");
		closeButton.setActionCommand("fromCloseButton");
		closeButton.addActionListener(controller);

		JPanel buttonPane = new JPanel();
		buttonPane.setLayout(new GridBagLayout());
		GridBagConstraints gBC3 = new GridBagConstraints();
		gBC3.fill = GridBagConstraints.BOTH;

		gBC3.gridx = 0;
		gBC3.gridy = 0;
		buttonPane.add(saveButton, gBC3);
		gBC3.gridx = 1;
		gBC3.gridy = 0;
		buttonPane.add(closeButton, gBC3);

		add(kandidatPane, BorderLayout.WEST);
		add(parteiPane, BorderLayout.EAST);
		add(buttonPane, BorderLayout.SOUTH);
	
		//pack();
		
    }
 

    // Setter fuer den Kandidatentext
    public void setKandidatText(String[] Kandidat)
    {
    	this.textKan11.setText(Kandidat[0]);
    	this.textKan21.setText(Kandidat[1]);
    	this.textKan31.setText(Kandidat[2]);
    	this.textKan41.setText(Kandidat[3]);
    	this.textKan51.setText(Kandidat[4]);
    	this.textKan61.setText(Kandidat[5]);
    	this.textKan71.setText(Kandidat[6]);
    	this.textKan12.setText(Kandidat[7]);
    	this.textKan22.setText(Kandidat[8]);
    	this.textKan32.setText(Kandidat[9]);
    	this.textKan42.setText(Kandidat[10]);
    	this.textKan52.setText(Kandidat[11]);
    	this.textKan62.setText(Kandidat[12]);
    	this.textKan72.setText(Kandidat[13]);
    	
    }

 
    // Setter fuer den Buttontext
    public void setButtonText(String text)
    {
    	this.saveButton.setText(text);

    }
 
    @Override
    // Event-Handling
    public void update(Observable arg0, Object eventCommand)
    {
        if (eventCommand.equals("done"))
        {
        	if(model.getButtonState())
        		setButtonText("Gespeichert");
        }

    }
}
